const app = getApp()
Page({
  data: {
    notice:'没有学生数据,请核对手机号和学校。',
    loadingHidden: false,//代表出现加载
    phone:'',
    link:'',
    user_name:'',
    user_id:'',
    class_text:'',
    user_type:'',
  },
  onLoad: function (options) {
    // this.getnostudentnotice();
    wx.setNavigationBarTitle({
      title: "选择学生"
    })
    var phone = options.phone;
    var link = options.link;
    var openid = getApp().globalData.openid;
    if (phone == '') {
      wx.showToast({
        title: '请返回输入手机号',
        image: '/images/error.png',
        duration: 2000
      })
      return
    }
    var that=this;
    wx.request({
      url: getApp().globalData.baseUrl + 'getMobileUserList',
      method: "GET",
      data: {
        phone: phone,
        openid: openid,
        link: link
      },
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        that.getnostudentnotice(link);
        // console.log(res);return;
        if(res.data.code==200){
          if (res.data.data.length>0){
            that.setData({
              studentdata: res.data.data});
          }
        }
        that.setData({loadingHidden: true})
      }
    })
  },
  selectstudent: function (e) {
    var user_id = e.currentTarget.dataset.id;
    var user_name = e.currentTarget.dataset.name;
    var class_text = e.currentTarget.dataset.class;
    var user_type = e.currentTarget.dataset.type;
    if (class_text == undefined || class_text==null){
      class_text=="";
    }
    if (user_id == "" || user_id == null || user_id == undefined) {
      wx.showToast({
        title: '网络错误,重新选择',
        image: '/images/error.png',
        duration: 2000
      })
      timer = setTimeout(function () {
        wx.redirectTo({
          url: '../binding/binding'
        })
      }, 2000);
      return;
    }
    let pages = getCurrentPages();
    let currPage = null; //当前页面
    let prevPage = null; //上一个页面
    if (pages.length >= 2) {
      currPage = pages[pages.length - 1]; //当前页面
      prevPage = pages[pages.length - 2]; //上一个页面
      if (prevPage) {
         prevPage.setData({
          user_name: user_name,
          user_id: user_id,
          class_text: class_text,
          user_type: user_type
        });
      }
    }
    wx.navigateBack({
      delta: 1
    })
  },
  onReady: function () {
  },

  onShow: function () {
    var that = this;
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];
  },

  onHide: function () {
  },
  onUnload: function () {
  },
  onPullDownRefresh: function () {
  },
  onReachBottom: function () {
  },
  onShareAppMessage: function () {
  },

  //获取提示语
  getnostudentnotice: function (options) {
    var self = this;
    var link = options;//域名
    wx.request({
      url: getApp().globalData.baseUrl + 'getnostudentnotice',
      method: "GET",
      data: {
        link: link
      },
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        if (res.data) {
          self.setData({
            notice: res.data
          })
        }
      }
    })
  },
  
})